<?php get_header();
$active_option = get_option('azio_style_option', 'option_not_set');?>

<?php get_template_part('block', 'slider') ?>

    <div id="main-container" class="homepage<?php echo ' ' . $active_option->main_container; ?>">
        <div class="floatted-box">
            <div class="offers-box container_12"><span class="blur-cover-left"></span> <span
                    class="blur-cover-right"></span>

                <div class="flexslider">
                    <ul class="slides">
                        <?php
                        $num_featured = ot_get_option('op_num_featured');
                        $featured_posts = Azio_Posts::getProducts($num_featured, '', 'featured_product', true); ?>
                        <?php
                        foreach ($featured_posts as $featured_post) {
                            $product_fields = Azio_Posts::getProductField($featured_post->ID);
                            ?>
                            <li>
                                <div class="tooltip-cover">
                                    <div class="tooltip">
                                        <span class="title"><?php echo $featured_post->post_title; ?></span>

                                        <div class="price">
                                            <?php if ($product_fields['giathitruong']): ?>
                                                <span class="old-price"><?php echo number_format($product_fields['giathitruong'], 0, ',', ','); ?> ₫</span><?php endif; ?>
                                            <?php if ($product_fields['giaban']): ?>
                                                <span class="new-price"><?php echo number_format($product_fields['giaban'], 0, ',', ','); ?> ₫</span><?php endif; ?>
                                        </div>
                                    </div>
                                </div>
                                <span class="cover"></span><a href="<?php echo $featured_post->permalink ?>" class="icomoon plus"
                                                              aria-hidden="true" data-icon="&#xe01a;"></a><img
                                    src="<?php echo $featured_post->image_thumbnail ?>" alt="<?php echo esc_attr($featured_post->post_title); ?>"/>
                            </li>
                        <?php
                        } // end foreach posts
                        ?>

                    </ul>
                </div>
            </div>
        </div>
        <!-- end .floatted-box -->
        <div class="container_12 full-container">

            <?php
            $num_featured = ot_get_option('op_num_index');
            $producttypes = Azio_Posts::getAllTopProducttype();

            //var_dump($producttypes);
            //var_dump($num_featured);
            foreach ($producttypes as $producttype):

                $child_terms = Azio_Posts::getTermByParent($producttype->term_id, 'producttype');
                $new_posts = Azio_Posts::getProducts($num_featured, $producttype->term_id, 'show_index', true);

                if ($new_posts):?>
                    <?php $producttype->link = get_term_link($producttype, 'producttype'); ?>
                    <div class="featured-module module clearfix">
                        <div class="box-heading">
                            <h3>
                                <a href="<?php echo $producttype->link ?>" title="<?php esc_attr($producttype->name) ?>"><?php echo $producttype->name ?></a>
                            </h3>
                            <?php if ($child_terms): ?>
                                <ul class="sub-heading">
                                    <?php foreach ($child_terms as $child_term) {
                                        echo '<li><a href="' . $child_term->permalink . '" title="' . esc_attr($child_term->name) . '">' . $child_term->name . '</a></li>';
                                    } ?>
                                </ul>
                            <?php endif; ?>
                        </div>
                        <div class="slides">
                            <?php
                            foreach ($new_posts as $new_post) {
                                $product_fields = Azio_Posts::getProductField($new_post->ID);
                                ?>
                                <div class="product-box grid_3">
                                    <a class="img-cover" href="<?php echo $new_post->permalink ?>">
                                        <img src="<?php echo $new_post->image_thumbnail ?>" alt="<?php echo esc_attr($new_post->post_title); ?>">
                                    </a>

                                    <div class="product-meta">
                                        <div class="title">
                                            <b><a href="<?php echo $new_post->permalink ?>"><?php echo $new_post->post_title; ?></a></b>
                                        </div>
                                        <div class="price">
                                            <?php if ($product_fields['giathitruong']): ?>
                                                <span class="old-price"><?php echo number_format($product_fields['giathitruong'], 0, ',', ','); ?> ₫</span><?php endif; ?>
                                            <?php if ($product_fields['giaban']): ?>
                                                <span class="new-price"><?php echo number_format($product_fields['giaban'], 0, ',', ','); ?> ₫</span><?php endif; ?>
                                        </div>
                                    </div>
                                    <!-- product-meta -->

                                    <ul class="product-action">
                                        <li>
                                            <div class="tooltip-wrapper"><span class="tooltip">Xem chi tiết</span>
                                            </div>
                                            <a href="<?php echo $new_post->permalink ?>" class="icomoon" aria-hidden="true" data-icon="&#xe01c;"></a>
                                        </li>
                                        <li>
                                            <div class="tooltip-wrapper"><span class="tooltip">Thêm vào giỏ</span>
                                            </div>
                                            <a href="javascript:void(0);" onClick="javascript:addOneToCart(this, <?php echo $new_post->ID ?>);" class="icomoon" aria-hidden="true" data-icon="&#x25e0;"></a>
                                        </li>
                                    </ul>
                                </div>
                                <!-- .product-box -->
                            <?php
                            } // end foreach posts
                            ?>
                        </div>
                        <!-- end .slides -->
                    </div>
                    <!-- .featured-module -->
                    <hr class="block-separator">
                <?php endif;
            endforeach ?>

            <?php $index_cat_id = ot_get_option('op_index_cat', '8');
            $index_cat = get_term($index_cat_id, 'category');
            $index_cat_link = get_term_link($index_cat, 'category');?>

            <div class="latest-blog clearfix">
                <div class="box-heading">
                    <h3><?php echo $index_cat->name ?></h3>
                    <a href="<?php echo $index_cat_link ?>" class="all-blog right">Xem tất cả</a>
                </div>
                <?php $article_posts = Azio_Posts::getPosts(3, $index_cat_id); ?>
                <?php
                $i = 1;
                foreach ($article_posts as $article_post) {
                    ?>
                    <article class="grid_4<?php if ($i % 3 == 0) echo " omega"; ?>">
                        <div class="meta">
                            <span class="date">
                                <span class="day"><?php echo date("d", strtotime($article_post->post_date)); ?></span>
                                <span class="month"><?php echo date("m", strtotime($article_post->post_date)); ?></span>
                            </span>

                            <div class="title">
                                <h4><?php echo Azio_Posts::cut_tring_by_char($article_post->post_title, 35); ?></h4>
                                <span><a href="<?php echo $index_cat_link ?>"><?php echo $index_cat->name ?></a></span>
                            </div>
                        </div>
                        <a class="img-cover" href="<?php echo $article_post->permalink ?>">
                            <img src="<?php echo $article_post->featured_image ?>" alt="news-image"> </a>

                        <div class="excerpt">
                            <p><?php echo Azio_Posts::cut_tring_by_char(strip_tags($article_post->post_content), 120) ?></p>
                        </div>
                        <a class="blog-link" href="<?php echo $article_post->permalink ?>"><i class="icomoon" aria-hidden="true"
                                                                                              data-icon="&#xe01a;"></i>Xem tiếp</a>
                    </article>
                    <?php
                    $i++;
                } // end foreach posts
                ?>
            </div>
            <!-- end .latest-blog -->
        </div>
        <!-- end .container_12 -->

        <?php get_template_part('block', 'baseinfo') ?>
        <!-- end .base-info -->
    </div>
    <!-- end #main-container -->




<?php get_footer(); ?>